from tw.forms.validators import Int, NotEmpty,UnicodeString,All,ForEach,DateConverter
from tw.forms.fields import TextField, TextArea, CheckBox, HiddenField, RadioButtonList
from tw.forms import CalendarDatePicker,TableForm,HiddenField,ListForm
from add_metadata import NakedDateConverter
from tw.api import Widget,WidgetsList
from tg import url
from tw.jquery.activeform import AjaxForm
#from ajaxsubmit import AjaxSubmit
from comboselect import ComboSelect

class UpdateParties(TableForm):
    template = "lifepyscle.widgets.templates.table_form"
    hover_help = True
    submit_text = "Update Parties"
    class fields(WidgetsList):
        parties_involved = ComboSelect(label_text=u"Parties Involved:",options=[],\
                validator=ForEach(Int()),\
                help_text=u"Available parties are on the left. Select (ctrl-click to select multiple) parties and move them to the right side. You can use a double click to move a party from left to right, or vice versa")
        record_id = HiddenField()

update_parties_form = UpdateParties("update_parties_form",action=url('/record/update_parties'))

class UpdateEvents(TableForm):
    effective_date = CalendarDatePicker(label_text=u'Effective Date:',date_format="%Y-%m-%d",validator=NakedDateConverter(format="%Y-%m-%d"),\
    button_text=u"Choose Effective Date",\
    help_text=u"Enter the effective date of the record. Additional events can be added later. The effective date is taken to be 00:00 UTC on the date provided")

class RemoteRiskFields(WidgetsList):
    hover_help=True
    record_id = HiddenField(id="record_id")
    risk = RadioButtonList(id='risk',name='risk',template="lifepyscle.widgets.templates.rbl",\
        label_text=u"Party Risk", help_text=u"")


remote_risk_form = TableForm(id="remote_risk_form",
                    hover_help = False,
                    fields=RemoteRiskFields(),
                    target="remote_risk_output",
                    dataType='json',
                    action="/party/remote_risk_update")

